﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Topology;

using Point = System.Drawing.Point;

using System.Drawing;

using System.Drawing.Drawing2D;



namespace FXnaGis
{
    [Serializable]
   public class FLineShape:FShape
    {

       public FLineShape(string id)
           : base(id)
       {


           List<Coordinate> test = new List<Coordinate>();

          // this._coords = new List<Coordinate>();
           this._line = new LineString(test);


          
 
       }


       public FLineShape(string id, List<Coordinate> coords):base(id)
       {

           this._line = new LineString(coords.CloneList<Coordinate>());

           
       }




      






       LineString _line;

       public LineString Line
       {
           get { return _line; }
           set {
               
               _line = value;

            
           
           
           }
       }



        /// <summary>
        /// 重置线条坐标
        /// </summary>
        /// <param name="coords"></param>

       public void ResetCoords(List<Coordinate> coords)
       {


           this._line = new LineString(coords.CloneList<Coordinate>());
 
       }




       public override void Move(double xOffset, double yOffset, double zOffset)
       {
          foreach (Coordinate c in this._line.Coordinates)
           {
               c.X += xOffset;
               c.Y += yOffset;
               c.Z += zOffset;
 
               
           }

           this._line.UpdateEnvelope();

       }


       public override void Draw(FMapArgs args)
       {
          


           LineStyle lineStyle = this.Parent.LineStyle;


           //查看外围状况先,允许外围不指定style值


           //if (style == null)
           //{
           //    lineStyle = LineStyle.DefaultStyle;

           //}
           //else
           //{
           //     lineStyle = style as LineStyle;
 
           //}

         


           List<Point> pts = new List<Point>();

           foreach (DotSpatial.Topology.Coordinate c in this.Line.Coordinates)
           {
               pts.Add(args.ProjToPixel(c));


           }


           //List<Point> intPoints = DuplicationPreventer.Clean(pts);
           if (pts.Count < 2)
           {

               return;
           }


           GraphicsPath path = new GraphicsPath();


           path.StartFigure();
           Point[] pointArray = pts.ToArray();
           path.AddLines(pointArray);


           //这里不需要闭合图形，因为这里绘制的是普通的线

           //path.CloseFigure();



           lineStyle.DrawPath(args.Device, path, 1);




           path.Dispose();


           


       }


       public override void DrawLable(FMapArgs args)
       {
           base.DrawLable(args);



           LableStyle ls = this.Parent.LableStyle;

           System.Drawing.Point pt = args.ProjToPixel(this._line.Coordinate);

           ls.DrawString(args.Device, this.Desc, pt);



       }

     


       public override bool Intersects(Envelope envelope)
       {
           return this._line.Intersects(envelope);

       }


       public override DotSpatial.Data.Extent Extent
       {
           get
           {
               return new DotSpatial.Data.Extent(this._line.Envelope);
           }
       }



      


    }
}
